import 'dart:async';

import 'package:flutter/material.dart';

class SplashPage extends StatefulWidget {
  @override
  _SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  int _secondsLeft = 300;
  Timer periodTimer;

  @override
  void initState() {
    super.initState();
    periodTimer = Timer.periodic(Duration(seconds: 1), (timer) {
      this.setState(() {
        _secondsLeft--;
      });
      if (_secondsLeft <= 0) {
        timer.cancel();
        Navigator.pushReplacementNamed(context, "start_page");
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        ConstrainedBox(
          constraints: BoxConstraints.expand(),
          child: Image.asset(
            "images/splash.png",
            fit: BoxFit.fill,
          ),
        ),
        Positioned(
          left: 10,
          top: 10,
          child: GestureDetector(
            onTapUp: (d) {
              periodTimer.cancel();
              Navigator.pushReplacementNamed(context, "start_page");
            },
            child: Container(
              width: 50,
              height: 50,
//              padding: EdgeInsets.all(0),
//              margin: EdgeInsets.all(0),
              decoration: new BoxDecoration(
                color: Color(0x0f00000f), // 底色
                shape: BoxShape.circle, // 圆形，使用圆形时不可以使用borderRadius
              ),
              child: Center(
                child: Text(
                  "跳${_secondsLeft}s",
                  textScaleFactor: 1,
                  style: TextStyle(color: Colors.amberAccent, fontFamily: "google", fontSize: 13),
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
